package edu.isistan.soc;

import java.math.BigInteger;

import org.springframework.oxm.Marshaller;
import org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint;

import edu.isistan.soc.model.GetWsdlMessagesCountRequest;
import edu.isistan.soc.model.GetWsdlMessagesCountResponse;
import edu.isistan.soc.model.ObjectFactory;

public class GetMessagesCountEndpoint extends
		AbstractMarshallingPayloadEndpoint {

	private final WsdlService wsdlService;

	public GetMessagesCountEndpoint(WsdlService theWsdlService,
			Marshaller marshaller) {
		super(marshaller);
		wsdlService = theWsdlService;
	}

	protected Object invokeInternal(Object request) throws Exception {

		GetWsdlMessagesCountRequest messagesCountRequest = (GetWsdlMessagesCountRequest) request;
		int count = wsdlService.getWsdlMessagesCount(messagesCountRequest.getWsdlLocation());
		GetWsdlMessagesCountResponse response = new GetWsdlMessagesCountResponse();
		response.setCount(BigInteger.valueOf(count));
		return response;
	}

}
